package cn.com.zpark.servlet_context;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.servlet_context
 * @ClassName: ServletContextDemo05
 * @Description:
 * @author: RZS
 * @date: 2021/11/10  18:06
 */
@WebServlet("/scd5.html")
public class ServletContextDemo05 extends HttpServlet {
    // 获取ServletContextDemo03绑定的数据
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取context对象
        ServletContext context = getServletContext();
        // 获取绑定值
        String user = (String) context.getAttribute("user");

        System.out.println(user);
    }
}

